using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DealerWorld.Forms
{
    public partial class repair_order : Form
    {
		static public List<string> lineItemReturn = new List<string>();
		static public Customer custForRO = new Customer(null);
		static public Vehicle vehForRO = new Vehicle(null);

        private RepairOrder ro;

        public repair_order(RepairOrder r)
        {
            InitializeComponent();

            ro = r;

            txb_auth_estimate.Text = ro.authEst;
            txb_cust_email.Text = ro.c.mainEmail;
            txb_cust_name.Text = ro.c.name;
            txb_cust_phone.Text = ro.c.mainPhone;
            txb_description.Text = ro.v.make + ", " + ro.v.model + ", " + ro.v.year + ", " + ro.v.color;
            txb_license.Text = ro.v.licensePlate;
            txb_mileage.Text = ro.v.mileage.ToString();
            txb_po_number.Text = ro.poNo;
            if (ro.prodDate != DateTime.MinValue) txb_promise_date.Value = ro.prodDate;
            txb_tag_number.Text = ro.tagNo;
            txb_total_line_estimate.Text = ro.totalLineEst;
            txb_unit_number.Text = ro.unitNo;
            txb_vin.Text = ro.v.vin;

        }

		private void button3_Click(object sender, EventArgs e)
		{
			new line_item().ShowDialog();

			if (lineItemReturn.Count != 0)
			{
				foreach (string l in lineItemReturn) {
					listBox1.Items.Add(l);
				}
			}

			lineItemReturn.Clear();
		}

		private void button2_Click(object sender, EventArgs e)
		{
			// Save a new RO.
			RepairOrder ro = new RepairOrder();

			ro.v.mileage = Int32.Parse(txb_mileage.Text.Trim());
			ro.serviceAdvisor = textBox4.Text.Trim();
			ro.tagNo = txb_tag_number.Text.Trim();
			ro.poNo = txb_po_number.Text.Trim();
			ro.authEst = txb_auth_estimate.Text.Trim();
			ro.totalLineEst = txb_total_line_estimate.Text.Trim();
			ro.contact = textBox16.Text.Trim();

			ro.promiseTime = DateTime.Parse(txb_promise_date.Text);

			foreach (string item in listBox1.Items)
			{
				ro.lineItems.Add(item);
			}

			Main.allOrders.Add(ro);

            MessageBox.Show("RO Successfully saved");
            this.Close();
		}

		private void button6_Click(object sender, EventArgs e)
		{
			new search_customer().ShowDialog();

			txb_cust_name.Text = custForRO.name;
			txb_cust_phone.Text = "555-555-5555";
			textBox7.Text = "555-555-5555";
			textBox8.Text = "555-555-5555";
			txb_cust_email.Text = "jeremy@geneharvey.com";
		}

		private void button5_Click(object sender, EventArgs e)
		{
			new search_vehicle().ShowDialog();

			txb_vin.Text = vehForRO.vin;
			txb_description.Text = vehForRO.licensePlate;
			txb_license.Text = "1998 Pontiac Grand Prix GTP";
		}

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}